/*
 * External Static Functions other modules will use.
 * 
 * This class also creates the static variable Map which creates the repository
 */
package Track;

/**
 *
 * @author Chris
 */
public class ExternFunc_1 {
    
    //Build Track Layout
    static Map TrackModel = new Map();
    
    
    
    //Train Functions
    //Add a train to the TrainList which is used in block transitions
    //Returns -1 on failure
    public static int addTrain(int lineID, int trainID){
        return TrackModel.Sys.addNewTrain(lineID, trainID);
    }
    
    //Clears element trainID of the TrainList
    public static void removeTrain(int trainID){
        TrackModel.Sys.removeOldTrain(trainID);
    }
   
    
    //Get RailInterface of the current block the head of the train is in
    public static RailInterface headBlockInfo(int TrainID){
        return TrackModel.getRailInfo(TrainID, 2);
    }
    
    //Called whenever a train's head enters a new block
    //A RailInterface for the new block is returned
    public static RailInterface headBlockTransition(int TrainID){
        return TrackModel.getRailInfo(TrainID, 1);
    }
    
    //Called whenever a train's tail exits a block
    //A RailInterface for the new last block is returned
    public static RailInterface tailBlockTransition(int TrainID){
        return TrackModel.getRailInfo(TrainID, 0);
    }
    
    
    //Track Controller Functions
    //gets a controllerInterface for the specified lin and block
    public static ControllerInterface getControllerInfo(int lineID, int BlockID){
        return TrackModel.getBlockData(lineID, BlockID);
    }
    //commits a modified controllerInterface to the repository
    public static int updateControllerInfo(int lineID, int blockID, ControllerInterface CI){
        return TrackModel.setBlockData(lineID, blockID, CI);
    }
    
    //Set the specified switch to the specified value
    public static int setSwitch(int switchID, int lineID, int val){
        return TrackModel.adjustSwitch(switchID, lineID, val);
    }
    
    //set the specified signal to the value specified by signalVal
    public static int setSignal(int lineID, int blockID, int signalVal){
        return TrackModel.setSignal(lineID, blockID, signalVal);
    }
    
    
}
